package com.konsung.ksdc.manager.machine;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.konsung.ksdc.R;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;

import butterknife.Bind;
import butterknife.ButterKnife;
import uk.co.senab.photoview.PhotoView;
import uk.co.senab.photoview.PhotoViewAttacher;

/**
 * 网络图片的全屏显示及缩放Activity
 */
public class NetPicActivity extends Activity {
    public static final String PIC_URL = "pic_url";
    @Bind(R.id.iv_pic)
    PhotoView ivPic;
    @Bind(R.id.iv_loading)
    ImageView ivLoading;
    private PhotoViewAttacher photoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_net_pic);
        ButterKnife.bind(this);
        ivLoading.setVisibility(View.VISIBLE);
        ivPic.setVisibility(View.GONE);
        String url = getIntent().getStringExtra(PIC_URL);
        Picasso.with(this)
                .load(url)
                .config(Bitmap.Config.RGB_565)
                .placeholder(R.drawable.pic_talkbox_sel)
                .error(R.drawable.pic_talkbox_sel)
                .into(ivPic, new Callback() {
                    @Override
                    public void onSuccess() {
                        ivLoading.setVisibility(View.GONE);
                        ivPic.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onError() {

                    }
                });
        photoView = new PhotoViewAttacher(ivPic);
        photoView.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
            @Override
            public void onPhotoTap(View view, float x, float y) {
                finish();
            }
        });
    }
}
